package cn.xc.controller;

import cn.xc.domian.User;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import javafx.beans.DefaultProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@DefaultProperties(defaultFallback = "fallbackMethod")
public class UserController {
    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand
    @GetMapping("/getById/{id}")
    public Object getById(@PathVariable("id") Long id) {
        String url = "http://user-server/getById/" + id;
        return restTemplate.getForObject(url, User.class);
    }


    public Object fallbackMethod(){
        return new User(-1l,"服務斷啦","用户服务不可以用了");
    }
}